using UnityEngine;
using Beyond;
using System;
using Rosiness;
using static AdsProxy;

public sealed class ADSManager : ModuleSingleton<ADSManager>,IModule
{
    DateTime dt;

    public void OnCreate(object createParam)
    {
        dt = DateTime.Now;
    }

    /// <summary>显示插屏或者评价 (用于结算)</summary>
    public void ShowInsAdOrReview()
    {      
        int pjkzValue = AppInfo.getSetting("pjkz", 0);
        bool bEvaluate = PlayerPrefs.GetInt("evaluate_1") == App.getAppVersion();
        if (bEvaluate || pjkzValue == 0 || !((DateTime.Now - dt).TotalMilliseconds >= pjkzValue * 60 * 1000) ||
            !GameState.is5StarsDialogTrue)
            ShowAdInterstitial();
        else
        {
            GameState.is5StarsDialogTrue = true;
            App.evaluateApp(true);    //评价
        }
    }

    /// <summary>单纯检测评价</summary>
    public void OnlyShowEvaluate()
    {
        int pjkzValue = AppInfo.getSetting("pjkz", 0);
        bool bEvaluate = PlayerPrefs.GetInt("evaluate_1") == App.getAppVersion();
        
        if (bEvaluate || pjkzValue == 0 || !((DateTime.Now - dt).TotalMilliseconds >= (pjkzValue * 60 * 1000)) ||
            !GameState.is5StarsDialogTrue) return;
        
        GameState.is5StarsDialogTrue = true;
        App.evaluateApp(true);
    }

    /// <summary>单独插屏广告，受开关控制影响</summary>
    public void OnlyShowInterstitialAd()
    {
        GameState.playingTimes++;
        var cpkzValue = AppInfo.getSetting("cpkz", 0);
        
        if (GameState.playingTimes % 2 != 0 && cpkzValue == 0)
            return;
        
        ShowAdInterstitial();
    }


    /// <summary>
    /// 单独插屏不受开关控制
    /// </summary>
    public void OnlyInAdWithoutToggle()
    {
        ShowAdInterstitial();
    }

    public void OnUpdate()
    {
    }

    public void OnGUI()
    {
    }
}
